#include "pause.h"
#include "ui_pause.h"

pause::pause(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::pause)
{
    ui->setupUi(this);
    this->setWindowFlags(this->windowFlags() &~ Qt::WindowMinMaxButtonsHint);

    ui->pauseTemp->setPlaceholderText("请输入暂停时的热室温度");
    this->setFixedSize(380, 195);
    this->setWindowTitle("暂停");
    ok = false;
    cusMsg = new CustomMessageBox();

    /* 暂停温度范围校验 */
    /* 设置字符合法性 */
    ui->pauseTemp->setValidator(new QDoubleValidator(0, 9, 1, this));

    connect(ui->ok, &QPushButton::clicked, this, [=](){
        if(ui->pauseTemp->displayText() == ""){
            cusMsg->show(this, CMsg::CWarning, "警告", "请先输入暂停时温度！");
            return;
        }
        else if(ui->pauseTemp->displayText().toDouble() < 30.0 || ui->pauseTemp->displayText().toDouble() > 100.0){
            cusMsg->show(this, CMsg::CWarning, "温度越界", "温度范围为30.0℃~100.0℃");
            return;
        }
        emit pause::sendPauseTemperature(ui->pauseTemp->displayText());
        ui->pauseTemp->clear();
        ok = true;
        this->close();
    });

}

pause::~pause()
{
    delete ui;
}

void pause::closeEvent(QCloseEvent *event){
    if(!ok){
        emit pause::dontPause();
    }
    ok = false;
}

